<template>
  <div class="home-page white-bg">
    <div class="user-wrapper">
      <div class="user-info">
        <img :src="avatar_url" class="user-avatar" />
        <div class="info-box">
          <div class="info-title">早上好，{{ userName }}</div>
          <div class="info-desc">欢迎使用，伏羲東方数字化智慧云平台</div>
        </div>
      </div>
      <div class="user-menu" @click="handleToCenter">
        个人中心
        <span class="icon-link"></span>
      </div>
    </div>
    <div class="column-box">
      <div class="column-title">我的数据</div>
      <div class="tools-box">
        <div class="tools-item" v-for="(item, index) in toolList"  :key="index">
          <div class="tools-icon">
            <img :src="item.icon" class="icon-img" alt="" />
          </div>
          <div class="tools-content">
            <div class="tools-title">{{ item.name }}</div>
            <div class="tools-value">{{ item.value }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="column-box">
      <div class="column-title">常用功能</div>
      <div class="list-box">
        <div
          class="list-item"
          v-for="(item, index) in listData"
          :key="index"
          @click="handleTo(item)"
          :style="{
            backgroundImage: 'url(' + item.icon + ')'
          }"
        >
          <div class="list-img">
            <!-- <img :src="item.icon" class="icon-img" alt="" /> -->
          </div>
          <div class="list-title">{{ item.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref,onMounted,computed} from "vue";
import api from "@/api";
import { useRouter } from "vue-router";
import { useGlobalStore } from "@/store/modules/global";
const store = useGlobalStore();
const router = useRouter();
const userName = computed(() =>  JSON.parse(localStorage.getItem("userInfo"))?.real_name);
const avatar_url = computed(() =>  JSON.parse(localStorage.getItem("userInfo"))?.avatar_url) || "./data/user-avatar.jpeg";
const handleToCenter = () => {
  router.push("/personal");
};
const toolList = ref([
  {
    name: "布置作业",
    icon: "./images/teacher/home-tool-1.png",
    value: 0,
  },
  {
    name: "授课次数",
    icon: "./images/teacher/home-tool-2.png",
    value: 0,
  },
  {
    name: "我的班级",
    icon: "./images/teacher/home-tool-3.png",
    value: 0,
  },
  {
    name: "数字孪生",
    icon: "./images/teacher/home-tool-4.png",
    value: 0,
  },
  {
    name: "AI测评",
    icon: "./images/teacher/home-tool-5.png",
    value: 0,
  },
]);
const listData = ref([
  { name: "标准实验库", icon: "./images/teacher/icon-home-1.png",path:'/standard-experimental-library' },
  { name: "学校实验库", icon: "./images/teacher/icon-home-2.png" ,path:'/school-experimental-library'},
  { name: "仪器百科", icon: "./images/teacher/icon-home-3.png",path:'/encyclopedia-of-experimental-instruments' },
  // { name: "标准实验库", icon: "./images/teacher/icon-home-4.png",path:'/standard-experimental-library' },
  // { name: "AI测评", icon: "./images/teacher/icon-home-5.png",path:'/standard-experimental-library' },
  { name: "作业", icon: "./images/teacher/icon-home-6.png",path:'/lab-work' },
  { name: "班级管理", icon: "./images/teacher/icon-home-7.png",path:'/my-class' },
  // { name: "我的", icon: "./images/teacher/icon-home-8.png",path:'/standard-experimental-library' },
]);
const handleTo = (item) => {
  store.setTile(item.name);
  router.push(item.path);
};
const getData = async () => {
  const res = await api.apiTeacherMyTeacherSummaryPost({});
  console.log(res)
  toolList.value[0].value = res.data.homework_count;
  toolList.value[1].value = res.data.experiment_count;
  toolList.value[2].value = res.data.class_count;
  toolList.value[3].value = res.data.twin_count;
  toolList.value[4].value = res.data.ai_count;

};
onMounted(() => {
  getData();
});
</script>
<style lang="less" scoped>
.home-page {
  padding: 0 16px;
  min-height: 100%;
  .user-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 0 0;
    border-bottom: 1px solid #e6ebf1;
    flex-wrap: wrap;
    .user-info {
      display: flex;
      align-items: center;
      margin-bottom: 25px;
      .user-avatar {
        width: 46px;
        height: 46px;
        border-radius: 50%;
        background-color: #ccc;
        margin-right: 10px;
      }
      .info-box {
        .info-title {
          font-family: PingFangSC-Medium;
          font-weight: 500;
          font-size: 16px;
          color: #262626;
          line-height: 26px;
          margin-bottom: 3px;
        }
        .info-desc {
          font-family: PingFangSC-Regular;
          font-weight: 400;
          font-size: 12px;
          color: #595959;
        }
      }
    }
    .user-menu {
      padding:0 10px;
      height: 40px;
      
      margin-bottom: 25px;
      background: #ffffff;
      border: 1px solid #bec4ca;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 8px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 14px;
      cursor: pointer;
      color: #262626;
      .icon-link {
        width: 16px;
        height: 16px;
        background: url("@/assets/icon-link.png") no-repeat;

        margin-left: 5px;
      }
    }
  }
  .column-box {
    margin-top: 14px;
    .column-title {
      padding: 16px 0;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 16px;
      color: #262626;
      line-height: 22px;
    }
  }
  .tools-box {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    .tools-item {
      width: 216px;
      padding: 18px 0;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      position: relative;
      @media screen and (max-width: 768px) {
        width: 50%;
        flex:auto;
        margin-bottom: 12px;
      }
      &::after {
        position: absolute;
        right: 0;
        content: "";
        top: 18px;
        bottom: 18px;
        width: 1px;
        box-shadow: inset -1px 0 0px 0px #e6ebf1;
      }
      &:last-child {
        &::after {
          display: none;
        }
      }
      .tools-icon {
        width: 46px;
        height: 46px;
        margin-right: 12px;
        .icon-img {
          width: 46px;
          height: 46px;
        }
      }
      .tools-content {
        .tools-title {
          font-family: PingFangSC-Regular;
          font-weight: 400;
          font-size: 14px;
          line-height: 20px;
          color: #262626;
        }
        .tools-value {
          font-family: PingFangSC-Medium;
          font-weight: 500;
          font-size: 18px;
          color: #262626;
          letter-spacing: 0;
          line-height: 26px;
        }
      }
    }
  }
  .list-box {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -12px;
    @media screen and (max-width: 768px) {
      justify-content: center;
    }
    .list-item {
      width: 200px;
      height: 250px;
      cursor: pointer;
      background-color: #e6f5ff;
      background-position: center center;
      background-repeat: no-repeat;
      border-radius: 12px;
      box-sizing: border-box;
      padding: 12px;
      margin: 0 12px 23px 12px;
      background-size:100% 100%;
      transition: all .3s ease-in-out;
      &:hover{
        background-size:110% 110%;
      }
      .list-img {
        height: 180px;
        margin-bottom: 12px;
        .icon-img {
          width: 176px;
          height: 180px;
        }
      }
      .list-title {
        width: 176px;
        height: 46px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-top: 1px solid #2626260f;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        font-size: 14px;
        color: #262626;
        text-align: center;
      }
    }
  }
}
</style>
